package com.happy3w.cmds.refactor.config;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

import java.util.List;
import java.util.Objects;

@Getter
@Setter
@Builder
@AllArgsConstructor
public class ModulePackageConfig {
    // com.abc.def:artifactId-1
    private String module;

    private List<ChangePackageItemConfig> items;

    public static ModulePackageConfig from(ModulePackageConfigVo modulePackageConfigVo) {
        return ModulePackageConfig.builder()
                .module(modulePackageConfigVo.getModule())
                .items(modulePackageConfigVo.getItems().stream()
                        .map(CpiConfigBuilder::build)
                        .toList()
                )
                .build();
    }

    public String changePackage(String fullClassName) {
        return items.stream()
                .map(item -> item.apply(fullClassName))
                .filter(Objects::nonNull)
                .findFirst()
                .orElse(null);
    }
}
